package com.atguigu.mvc.controller;

import com.atguigu.mvc.bean.User;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.crypto.interfaces.PBEKey;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @date: 2021/12/23 14:09
 * @description:
 */

@Controller
public class HttpController {


    @RequestMapping("/testRequestBody")
    public String testRequestBody(@RequestBody String requestBody){
        System.out.println("requestBody="+requestBody);
        return "success";
    }
    @RequestMapping("/testRequestEntity")
    public String testRequestEntity(RequestEntity<String> requestEntity){
        System.out.println("请求头："+requestEntity.getHeaders());
        System.out.println("请求体："+requestEntity.getBody());
        return "success";
    }

    @RequestMapping("/testResponse")
    public void testResponse(HttpServletResponse response) throws IOException {
        response.getWriter().println("hello  response!!!");
    }

    @RequestMapping("/testResponseBody")
    @ResponseBody
    public String testResponseBody(){

        return "success"  ;
    }
    @RequestMapping("/testResponseUser")
    @ResponseBody
    private User testResponseUser(){

        return new User(1001,"admin","123456","男",23);
    }
    @RequestMapping("/testAxios")
    @ResponseBody
    private String testAxios(String username,String password){
        System.out.println(username+","+password);
        return username+","+password;
    }
}
